import instance from '../../utils/axios.js'

import { getToken } from '../../utils/token.js'

const getChannels = () => {
    return instance({
        url: '/v1_0/user/channels',
        method: 'get'
    })
}

const getArticle = ({ channel_id, timestamp }) => {
    return instance({
        url: '/v1_1/articles',
        method: 'get',
        params: {
            with_top: 1, //是否需要置顶，给1写死即可
            channel_id,
            timestamp
        }
    })
}

export { getChannels, getArticle }

const getArticleInfo = id => {
    return instance({
        url: `/v1_0/articles/${id}`,
        method: 'get'
    })
}
export { getArticleInfo }

const getSuggestList = value => {
    return instance({
        url: `/v1_0/suggestion`,
        method: 'get',
        params: {
            q: value
        }
    })
}

export { getSuggestList }

//关注
const toFollow = ({ target }) => {
    return instance({
        url: `/v1_0/user/followings`,
        method: 'post',
        data: {
            target
        }
    })
}
const notFollow = target => {
    return instance({
        url: `/v1_0/user/followings/${target}`,
        method: 'delete'
    })
}

export { toFollow, notFollow }

//点赞
const toPoint = id => {
    return instance({
        url: `/v1_0/article/likings`,
        method: 'post',
        data: {
            target: id
        }
    })
}
const notPoint = id => {
    return instance({
        url: `/v1_0/article/likings/${id}`,
        method: 'delete'
    })
}
export { toPoint, notPoint }

//不喜欢
const disLike = id => {
    return instance({
        url: `/v1_0/article/dislikes`,
        method: 'post',
        data: {
            target: id
        }
    })
}
const notDisLike = id => {
    return instance({
        url: `/v1_0/article/dislikes/${id}`,
        method: 'delete'
    })
}
export { disLike, notDisLike }

//搜索历史
const getHistory = () => {
    return instance({
        url: `/v1_0/search/histories`,
        method: 'get',
        headers: { Authorization: `Bearer ${getToken().token}` }
    })
}
export { getHistory }
//删除历史
const delHistory = () => {
    return instance({
        url: `/v1_0/search/histories`,
        method: 'delete',
        headers: { Authorization: `Bearer ${getToken().token}` }
        // message: item
    })
}
export { delHistory }

//搜索结果
const resSearch = params => {
    return instance({
        url: `/v1_0/search`,
        method: 'get',
        params
        //     : {
        //     q: keyword
        // }
    })
}
export { resSearch }